<?php
class StudentfotosController extends AppController {

	var $name = 'Studentfotos';
	var $helpers = array('Html', 'Form');

	function index() {
		$this->Studentfoto->recursive = 0;
		$this->set('studentfotos', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid Studentfoto', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('studentfoto', $this->Studentfoto->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Studentfoto->create();
			if ($this->Studentfoto->save($this->data)) {
				$this->Session->setFlash(__('The Studentfoto has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The Studentfoto could not be saved. Please, try again.', true));
			}
		}
		$students = $this->Studentfoto->Student->find('list');
		$this->set(compact('students'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid Studentfoto', true));
		//	$this->redirect(array('action' => 'index'));
			$this->redirect(array('action' => '/'));
		}
		if (!empty($this->data)) {
			if ($this->Studentfoto->save($this->data)) {
				$this->Session->setFlash(__('The Studentfoto has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The Studentfoto could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Studentfoto->read(null, $id);
		}
		$students = $this->Studentfoto->Student->find('list');
		$this->set(compact('students'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for Studentfoto', true));
			$this->redirect(array('action' => 'index'));
		}
		if ($this->Studentfoto->del($id)) {
			$this->Session->setFlash(__('Studentfoto deleted', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->Session->setFlash(__('The Studentfoto could not be deleted. Please, try again.', true));
		$this->redirect(array('action' => 'index'));
	}

	function changefoto() {
		$student_id = $this->data['Studentfoto']['student_id'];
		$this->set('student_id', $student_id);
	}
}
?>